//
//  MainNaviViewController.m
//  YiLiao-Doctor
//
//  Created by 糖otk on 2017/10/31.
//  Copyright © 2017年 Burining. All rights reserved.
//

#import "MainNaviViewController.h"
#import "UIView+Frame.h"
@interface MainNaviViewController ()<UIGestureRecognizerDelegate>

@end

@implementation MainNaviViewController

+ (void)initialize
{
    /** 设置UINavigationBar */
    UINavigationBar *bar = [UINavigationBar appearance];
    [bar setTranslucent:false];
    [bar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackGround"] forBarMetrics:UIBarMetricsDefault];
    
    // 设置标题文字属性
    NSMutableDictionary *barAttrs = [NSMutableDictionary dictionary];
    barAttrs[NSFontAttributeName] = [UIFont boldSystemFontOfSize:16];
    barAttrs[NSForegroundColorAttributeName] = [UIColor whiteColor];
    [bar setTitleTextAttributes:barAttrs];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
 
    [self.navigationBar setShadowImage:[UIImage new]];
    self.interactivePopGestureRecognizer.delegate = self;

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    
    if (self.childViewControllers.count >= 1) {
        // 左上角的返回
        UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [backButton setTitle:@"" forState:UIControlStateNormal];
        [backButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [backButton setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
        [backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
        [backButton sizeToFit];
        backButton.width = 50;
        backButton.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 30);
//        backButton.backgroundColor = [UIColor yellowColor];
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
        viewController.hidesBottomBarWhenPushed = YES; // 隐藏底部的工具条
            [backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];

        
    }
    
    [super pushViewController:viewController animated:animated];
}

- (void)back
{
    [self popViewControllerAnimated:YES];
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    if (self.childViewControllers.count == 1) {
        return NO;
    } else {
        return YES;
    }
    
}


@end
